<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>修改供货单</title>
<link href="${request.getContextPath()}/Public/assets/admin/css/css.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/font-awesome/css/font-awesome.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/simple-line-icons/simple-line-icons.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/css/bootstrap.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/uniform/css/uniform.default.css"
	rel="stylesheet" type="text/css">
<link rel="${request.getContextPath()}/Public/stylesheet"
	type="text/css"
	href="assets/global/plugins/jquery-notific8/jquery.notific8.min.css" />
<link
	href="${request.getContextPath()}/Public/assets/global/css/components-rounded.css"
	id="style_components" rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/plugins.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/layout.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/themes/default.css"
	rel="stylesheet" type="text/css" id="style_color">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/custom.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/global/css/kkpager.css"
	rel="stylesheet" type="text/css">
<link
	href="${request.getContextPath()}/Public/assets/admin/css/common.css"
	rel="stylesheet" type="text/css">
<link rel="shortcut icon"
	href="${request.getContextPath()}/Public/assets/global/plugins/datatables/media/images/favicon.ico">
<link href="${request.getContextPath()}/Public/css/customerDetail.css"
	rel="stylesheet" type="text/css">
<script type="text/javascript" src="${request.getContextPath()}/Public/My97DatePicker/WdatePicker.js"></script>
<script>
	BASE_URL = '${request.getContextPath()}'
</script>
<style type="text/css">
* {
	font-size: 14px;
}

#buyfrom label.error {
	color: Red;
	font-size: 13px;
	margin-left: 5px;
	padding-left: 16px;
	background: left no-repeat;
}

.commonBtn {
	margin: 0 5px;
}

.normalBtn {
	border: 1px solid #C0C1B4;
	color: #555;
	background-color: #fff;
}
div.radio{
    vertical-align: bottom;
}

#suppImg{
	width: 700px;
	text-align: left;
	margin-top: 10px;
}
#suppImg div{
	margin-right:5px;
	display:inline-block;
	width: 100px;
	position:relative;
}
#suppImg .delImg{
	position: absolute;
	left:84px;
	top: 0;
	cursor:pointer;
}
</style>

</head>
<body>
<div class="page-header">
	<!--头部开始-->
	<#include "/include/top.html" />
	<!-- 头部信息结束 -->
	<!-- 头部菜单开始 -->
	<#include "/include/top_menu.html" />
	<!-- 头部菜单结束 -->
</div>
<div class="page-container">
		<div class="page-content">
			<div class="container-fluid">
				<!-- 当前位置提示开始 -->
				<ul class="page-breadcrumb breadcrumb">
					<li class="active">
						当前位置: 废金属管理>>供货单管理>>修改供货单
					</li>
				</ul>
				<div class="row margin-top-10">
					<div class="col-md-12">
						<div class="portlet light bordered" align="center">
							<form class="form-horizontal" id="poolfrom">
								<input type="hidden" value="${imgAddr}" id="hiddimg" name="hiddimg"/>
								<input type="hidden" value="${(supp.id)!}" name="supplyId"/>
								<p align="left">
								<h3 style="font-weight: bold;">修改供货单</h3>
								</p>
								<div style="clear: both;"></div>
								<br> 
								<div class="form-group">
									<label class="col-sm-2 control-label">分类：</label>
									<div class="col-sm-2" style="width: 150px;" >
										<select name="itemid" id="itemid" class="form-control">
											<#list item as it>
												<option <#if supp?? && supp.itemId==it.id>selected</#if> value="${(it.id)!}" class="${(it.id)}">${(it.name)!}</option> 
											</#list>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">货物所在地：</label>
									<div style="width:110px;" class="col-sm-2">
										<select class="form-control" name="goodsProv" id="goodsProv" onchange="setChildAreas()">
											<#list areas as area>
												<option value="${(area.id)!''}" <#if supp?? &&supp.goodsProv=area.id>selected</#if>>${(area.name)!''}</option>
											</#list>
										</select>
									</div>
									<div class="col-sm-2" id="city" style="display: none;width: 150px;" >
										<select class="form-control" name="goodsCity" id="goodsCity"></select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label ">信息标题：</label>
									<div class="col-sm-2" style="width: 150px;">
										<input style="width: 200px;" type="text" class="form-control" value="${supp.infoTitle!''}" id="infoTitle" name="infoTitle">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">供货详情：</label>
									<div class="col-sm-2">
										<textarea name="description" id="description" style="width: 280px; height: 60px;">${supp.description!''}</textarea>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label ">数量：</label>
									<div class="col-sm-2">
										<input type="text" class="form-control" value="${supp.usableQuantity?string('#.#####')}" id="usableQuantity" name="usableQuantity">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">价格：</label>
									<div style="width: 150px;" class="col-sm-2" >
										<input type="text" id="price" name="price" value="${supp.price!''}" class="form-control"/>
									</div>
									<div class="col-sm-2" style="width: 120px;" >
										<select name="priceUnit" id="priceUnit" class="form-control" onchange="">
											<option value="0" <#if supp??&&supp.priceUnit??&&supp.priceUnit==0> selected="selected" </#if>>元</option>
											<option value="1" <#if supp??&&supp.priceUnit??&&supp.priceUnit==1> selected="selected" </#if>>美元</option>
										</select>
									</div>
									<div style="width: 100px; line-height: 30px; height: 30px;" class="col-sm-2">
										<input onclick="manyicheck();" id="priceNegotiable" name="priceNegotiable" type="checkbox" value="1" class="checkboxes" <#if supp.priceNegotiable?? && supp.priceNegotiable==1 >checked</#if>>面议
									</div>
								</div>	
								<div class="form-group">
									<label class="col-sm-2 control-label">价格说明：</label>
									<div class="col-sm-2" style="width: 150px;" id="divprice1" >
										<select name="priceExplain" id="priceExplain" class="form-control">
											<#list priceExplainList as pel>
												<option <#if supp?? && supp.priceExplain==pel.id>selected</#if> value="${(pel.id)!}">${(pel.name)!}</option> 
											</#list>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">交货方式：</label>
									<div class="col-sm-2" style="width: 150px;" id="deliverys" >
										<select name="delivery" id="delivery" class="form-control">
											<#list listDel as del>
												<option <#if supp?? && supp.delivery==del.id>selected</#if> value="${(del.id)!}">${(del.name)!}</option> 
											</#list>
										</select>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label ">商品图片：</label>
									<div class="col-sm-2">
										<table>
											<tr>
												<td>
													<input type="file" id="file" name="file" style="width:0;height:0;" onchange="getfilename()"/>
													<input type="hidden" id="imgPath" name="imgPath" value=""/>
													<input type="button" onclick="triggerGetfilename()"  value="上传图片">
												</td>
												<td></td>
											</tr>
											<tr>
												<td>
													<div id="suppImg">
														<#list suppImg as img>
															<div id='${img.imgName?substring(0, img.imgName?index_of("."))}'>
																<img id="imgs" name="imgs" style="width:100px; height:100px;" src="${img.name}"/>
																<img class="delImg" src="${request.getContextPath()}/Public/images/supply/delImg.png" onclick="deleteImg('${img.imgName}')" />
															</div>
														</#list>
													</div>
												</td>
												<td>
													
												</td>
											</tr>
										</table>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label">信息有效期：</label>
									<div style="width: 100px;" class="col-sm-2">
										<label><input type="radio" id="expiryType" name="expiryType" value="0" <#if supp.expiryType?? && supp.expiryType==0 >checked</#if> >一周</label>
									</div>
									<div style="width: 100px;" class="col-sm-2">
										<label><input type="radio" id="expiryType" name="expiryType" value="1" <#if supp.expiryType?? && supp.expiryType==1 >checked</#if> >一个月</label>
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-2 control-label ">手机：</label>
									<div style="width: 150px;" class="col-sm-2">
										<input style="width: 200px;" type="text" class="form-control" <#if supp.isCreatedByCustomer ?? && supp.isCreatedByCustomer == 1> disabled="disabled"</#if> value="${supp.phone!''}" id="phone" name="phone">
									</div>
								</div>
									<div class="form-group">
										<label class="col-sm-2 control-label ">发布时间：</label>
										<div class="col-sm-2">
											<input type="text" class="form-control" disabled="disabled" value="${supp.createdAt!''}" id="createdAt" name="createdAt">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label ">更新时间：</label>
										<div class="col-sm-2">
											<input type="text" class="form-control" disabled="disabled" value="${supp.updatedAt!''}" id="updatedAt" name="updatedAt">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label ">最后修改人：</label>
										<div class="col-sm-2">
											<input type="text" class="form-control" disabled="disabled"
											<#if supp ?? && supp.isUpdatedByCustomer ?? && supp.isUpdatedByCustomer == 0>
											 	value="${supp.uname!''}" 
											</#if>
											<#if supp ?? && supp.isUpdatedByCustomer ?? && supp.isUpdatedByCustomer == 1>
											 	<#if supp.customerName ?? && supp.customerName != ''>
													value="${supp.customerName!''}"
												<#else>
													value="${supp.nickName!''}"
												</#if>
											</#if>
											id="createdBy" name="createdBy">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">信息状态：</label>
										<div style="width: 100px;" class="col-sm-2">
											<label><input type="radio" id="infoStatus" onclick="showAdoptReason()" name="infoStatus" value="1"
											<#if supp.infoStatus?? && supp.infoStatus==1 >checked</#if>>通过</label>
										</div>
										<div style="width: 100px;" class="col-sm-2">
											<label><input type="radio" id="infoStatus" onclick="showAdoptReason()" name="infoStatus" value="2" 
											<#if supp.infoStatus?? && supp.infoStatus==2 >checked</#if>>未通过</label>
										</div>
										<div style="width: 100px;" class="col-sm-2">
											<label><input type="radio" id="infoStatus" onclick="showAdoptReason()" name="infoStatus" value="0"
											<#if supp.infoStatus?? && supp.infoStatus==0 >checked</#if>>待审核</label>
										</div>
										<div style="width: 100px;" class="col-sm-2">
											<label><input type="radio" id="infoStatus" onclick="showAdoptReason()" name="infoStatus" value="3" 
											<#if supp.infoStatus?? && supp.infoStatus==3 >checked</#if>>过期</label>
										</div>
										<div style="width: 100px;" class="col-sm-2">
											<label><input type="radio" id="infoStatus" onclick="showAdoptReason()" name="infoStatus" value="4"
											<#if supp.infoStatus?? && supp.infoStatus==4 >checked</#if>>删除</label>
										</div>
									</div>
										<div class="form-group" id="showstatus" style="display: none;">
											<label class="col-sm-2 control-label ">未通过原因：</label>
											<div class="col-sm-2">
												<input type="text" class="form-control" value="${supp.auditedComment!''}" id="auditedComment" name="auditedComment">
											</div>
										</div>
								<div class="form-group">
									<div class="col-sm-offset-2 col-sm-10">
										<button id="Button" onclick="javascript :history.back(-1);"
											type="button" class="btn green pull-left">
											返回 <i class="m-icon-swapright m-icon-white"></i>
										</button>

										<button type="button" id="savetButton"
											class="btn green pull-left">
											保存<i class="m-icon-swapright m-icon-white"></i>
										</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- 内容结束 -->
	<!-- 底部开始 -->
	<#include "/include/foot.html" />
	<!-- 底部结束 -->
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-migrate.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-ui/jquery-ui.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap/js/bootstrap.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-hover-dropdown/bootstrap-hover-dropdown.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-slimscroll/jquery.slimscroll.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.blockui.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery.cokie.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/uniform/jquery.uniform.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/jquery-notific8/jquery.notific8.min.js">
	</script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/scripts/metronic.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/layout.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/global/plugins/kkpager.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/commonUtils.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/priceFloat.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/tc.min.js"
	type="text/javascript"></script>
<script
	src="${request.getContextPath()}/Public/assets/admin/scripts/ajaxfileupload.js"
	type="text/javascript"></script>

<script type="text/javascript" src="${request.getContextPath()}/Public/js/ajaxfileupload.js"></script>
<!-- select2控件 -->
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.js"></script>
<script type="text/javascript" src="${request.getContextPath()}/Public/assets/global/plugins/select2/select2_locale_zh-CN.js"></script>
<link href="${request.getContextPath()}/Public/assets/global/plugins/select2/select2.css" rel="stylesheet" type="text/css">
<script>
jQuery(document).ready(function() {	
	   Metronic.init(); // init metronic core componets
	   Layout.init(); // init layout
	   setChildAreas();
	   showAdoptReason();
	   manyicheck();
	});

//面议禁用价格框	
function manyicheck(){
	var mianyi= $("input[name=priceNegotiable]:checked").val();
	if(mianyi==1){
		$("#price").attr("disabled","disabled");
		$("#price").val("");
	}else{
		$("#price").attr("disabled",false);
		
	}
}	

var imgAddr = "${imgAddr}";
function triggerGetfilename(){
	$("#file").click();
}
function getfilename(){
	if(!$("#file").val()){
		alert("上传文件为空");
		return;
	}
	if($("#suppImg>div").length >= 6){
		alert("只能上传6张图片");
		return;
	}
	$.ajaxFileUpload({
		url : "${request.getContextPath()}/supply/uploadmethod.do",
		secureuri : false,
		fileElementId : 'file', // 文件选择框的id属性
		dataType : 'json', // 服务器返回的格式，可以是json
		success : function(data){
			if (data.code == "000000") {
				if(imgAddr!='') imgAddr +=",";
				imgAddr += data.data;
				var address = data.imgServerAddress+data.data;
				var html = '<div id="'+data.data.substr(0, data.data.indexOf('.'))
							+'"><img id="imgs" name="imgs" style="width:100px; height:100px;" src="'
							+ address + '" /><img class="delImg" src="${request.getContextPath()}/Public/images/supply/delImg.png" onclick="deleteImg(\''
							+ data.data + '\')" /></div>';
				$("#suppImg").append(html);
				$("#hiddimg").val(imgAddr);
			}else{
			    alert("上传失败");
			}
		},
		error : function(data, e) { 
			console.log("请求服务器失败" + e);
		}
	});
}
//删除图片
function deleteImg(delimg){
	//debugger;
	var imgadd;
	var add = imgAddr.split(",");
	
	for(var i=0;i<add.length;i++){
		if(add[i] == delimg){
			add.splice(i, 1);
			break;
		}
	}
	imgAddr = '';
	for(var i=0;i<add.length;i++){
		if(imgAddr!=''){
			imgAddr+=",";
		}
		imgAddr += add[i];
	}
	$("#"+delimg.substr(0, delimg.indexOf('.'))).remove();
	$("#hiddimg").val(imgAddr);
}

$("#savetButton").bind("click",
		function() {
			var itemid = $("#itemid").val();
			var prov = $("#goodsProv").val();
			var city = $("#goodsCity").val();
			var infoTitle = $("#infoTitle").val();
			var description = $("#description").val();
			var usableQuantity = $("#usableQuantity").val();
			var price = $("#price").val();
			var priceUnit = $("#priceUnit").val();
			var priceExplain = $("#priceExplain").val();
			var priceNegotiable = $("#priceNegotiable").val();
			var delivery = $("#delivery").val();
			var expiryType = $("#expiryType").val();
			var phone = $("#phone").val();
			var auditedComment = $("#auditedComment").val();
			
			var status = $("input[name=infoStatus]:checked").val();
			if(status == 2){
				if(auditedComment == null || auditedComment == ''){
					alert("请输入未通过原因");
					return;
				}
			}
			
			if (prov == null || prov == '') {
				alert("请选择所在省");
				return;
			}
			if (infoTitle == null || infoTitle == '') {
				alert("请输入信息标题");
				return;
			}
			if (infoTitle.length < 2 || infoTitle.length > 20) {
				alert("信息标题应该在2-20个字数以内");
				return;
			}
			if (description == null || description == '') {
				alert("请输入供货详情");
				return;
			}
			if (description.length > 200) {
				alert("供货详情应该在200个字数以内");
				return;
			}
			if (usableQuantity == null || usableQuantity == '') {
				alert("请输入数量");
				return;
			}
			if ((price == null || price == '') && (priceNegotiable == null || priceNegotiable == '')) {
				alert("请输入价格或者选择面议");
				return;
			}
			if (phone == null || phone == '') {
				alert("请输入手机号码");
				return;
			}
			
			var reg = /^[0-9]+([\.][0-9]{0,5})?$/;
			if (!reg.test(usableQuantity)) {
				alert("格式错误,数量为5位小数的数字！");
				return;
			}
			var reg1 = /^[0-9]+([\.][0-9]{0,2})?$/;
			if(price&&price!=null){
			if (!reg1.test(price)) {
				alert("格式错误,价格为2位小数的数字！");
				return;
			}
			}
			reg2 =/1\d{10}/;
			if (!reg2.test(phone)) {
				alert("格式错误,请输入正确的手机号码！");
				return;
			}
			$.ajax({
				url : "${request.getContextPath()}/supply/updateSupply.do",
				type : "post",
				dataType : "json",
				async : false,
				data : $("#poolfrom").serialize(),
				success : function(result) {
					if(result.success == 1) {
						alert("修改成功");
						window.location.href = "${request.getContextPath()}/supply/orderListWeb.do?status=1";
					}else if(result.success == 2) {
						alert("数量或价格超出限制");
					}else if(result.success == 3) {
						alert("至少上传一张图片");
					}else if(result.success == 4) {
						alert("价格不能为空");
					}else{
						alert("修改失败");
					}
				}
			});
		});
		

	//显示未通过原因
	function showAdoptReason() {
		var status = $("input[name=infoStatus]:checked").val();
		if (status == 2) {
			$("#showstatus").show();
		} else {
			$("#showstatus").hide();
			$("#auditedComment").val("");
		}

	}
	//选择省级地区
	function setChildAreas(){
		var parentId = $("#goodsProv").val();
		if(parentId){
			priceExplain(parentId);
			delivery(parentId);
			var city=${supp.goodsCity};
			$("#goodsCity").find('option').remove();
			$.ajax({
				type : "POST",
				url : "${request.getContextPath()}/Purchase/getChildAreas.do?parentId="+parentId,
				dataType : "json",
				success : function(areas) {
					if(areas && areas instanceof Array && areas.length>0){
						$("#city").show();
						var area;
						for(var i=0;i<areas.length;i++){
							area = areas[i];							
							if(area && typeof area=='object'){
								if(city && city==area.id ){
									$("#goodsCity").append('<option  selected value="'+ area.id +'">'+ area.name +'</option>');
								}else{
									$("#goodsCity").append('<option  value="'+ area.id +'">'+ area.name +'</option>');
								}
							}
						}
					}else{
						if(areas==null){
							$("#city").hide();
						}
					}
				}
			});
		}
	}

	//国外和国内价格说明切换
	function priceExplain(parentId){ 
		var flag=1;
		if(parentId==392){
			flag=2;//海外 
		}
		var priceExplain=${(supp.priceExplain)!};
		$.ajax({
			type : "POST",
			url : "${request.getContextPath()}/Purchase/priceExplain.do?flag="+flag,
			dataType : "json",
			success : function(data) {
				if(data && data instanceof Array && data.length>0){
					var html="<select name='priceExplain' id='priceExplain' class='form-control'>";
					for(var i=0;i<data.length;i++){
						da = data[i];		
						if(da && typeof da=='object'){
							if(priceExplain==da.id){
								html+='<option  selected value="'+ da.id +'">'+ da.name +'</option>'	
							}else{
								html+='<option  value="'+ da.id +'">'+ da.name +'</option>'	
							}
						}
					}
					$("#divprice1").html(html+="</select>");
				}
			}
		});
	}
	//国外和国内交货方式切换
	function delivery(parentId){ 
		var flag=1;
		if(parentId==392){
			flag=2;//海外 
		}
		var delivery=${(supp.delivery)!};
		$.ajax({
			type : "POST",
			url : "${request.getContextPath()}/supply/queryDelivery.do?flag="+flag,
			dataType : "json",
			success : function(data) {
				if(data && data instanceof Array && data.length>0){
					var html="<select name='delivery' id='delivery' class='form-control'>";
					for(var i=0;i<data.length;i++){
						da = data[i];									
						if(da && typeof da=='object'){
							if(delivery==da.id){
								html+='<option  selected value="'+ da.id +'">'+ da.name +'</option>'	
							}else{
								html+='<option  value="'+ da.id +'">'+ da.name +'</option>'	
							}
						}
					}
					$("#deliverys").html(html+="</select>");
				}
			}
		});
	}
</script>

</body>
</html>